package com.findmeastore.util;

import java.util.regex.Pattern;

public class ValidateUtil {
	public static final Pattern emailPattern = Pattern.compile("([a-zA-Z_\\.\\-0-9]+)@[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9]+){1,}$");
	public static final Pattern urlPattern = Pattern.compile("^http[s]?://[^ ]+$");
	private static final String MOBILE_PATTERN = "^([1-9][0-9]{9})$";
	private static final String TOLL_FREE_PATTERN = "^([1-9][0-9]{9,11})$";
	private static final String PHONE_PATTERN = "^[1-9][0-9]{6,10}$";
	private static final String STD_CODE_PATTERN = "^([0][1-9][0-9]{1,3})$";

	public static boolean isValidEmail(String email) {
		return emailPattern.matcher(email).matches();
	}

	public static boolean isValidUrl(String url) {
		return urlPattern.matcher(url).matches();
	}
	
	public static boolean containsChar(String searchText){
		searchText = searchText.trim().replace("*","");
    searchText = searchText.replace("%","");
    //We can not use StringUtil.isEmpty method because "* *" is valid search string.
    return searchText.length() > 0 ? true : false;
  }
  public static boolean isValidMobile(String mobileNumber){
    return mobileNumber.matches(MOBILE_PATTERN);
  }

  public static boolean isValidPhone(String phoneNumber){
    return phoneNumber.matches(PHONE_PATTERN);
  }

  public static boolean isValidStdCode(String stdCode){
    return stdCode.matches(STD_CODE_PATTERN);
  }
  public static boolean isValidTollFree(String tollFreeNumber){
    return tollFreeNumber.matches(TOLL_FREE_PATTERN);
  }
}
